class Solution(object):
    def findMaxAverage(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: float
        """
        n = len(nums)
        min_val = min(nums)
        max_val = max(nums)

        def search(mid):
            sums = [nums[i] - mid for i in range(n)]

            for i in range(1, n):
                sums[i] += sums[i - 1]
            if sums[k - 1] >= 0:
                return True
            min_prex = 0
            for i in range(n - k):
                min_prex = min(min_prex, sums[i])
                if sums[i + k] >= min_prex:
                    return True
            return False

        while max_val - min_val >= 10 ** (-5):
            mid = (min_val + max_val) / 2
            if search(mid):
                min_val = mid
            else:
                max_val = mid

        return (min_val + max_val) / 2


data = Solution()
nums = [5]
k = 1
print(data.findMaxAverage(nums, k))
